#include "DerivationTree.h"
#include "EqualInstruction.h"
#include <cmath>

EqualNode::EqualNode() : NodeTree_CRTP<EqualNode>() { }

EqualNode::EqualNode(const AutoPointer<NodeTree>& _left, const AutoPointer<NodeTree>& _right) : NodeTree_CRTP<EqualNode>(), left(_left), right(_right) { }

EqualNode::EqualNode(const EqualNode& copy) : NodeTree_CRTP<EqualNode>(copy), left(copy.left), right(copy.right) { }

bool EqualNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	left->execute(LVM);
	right->execute(LVM);
	AutoPointer<TreeExpression::Expression> second = LVM->top();
	LVM->pop();
	AutoPointer<TreeExpression::Expression> first = LVM->top() ;
	LVM->pop();
	first->addLeaf(second);
	TreeExpression::EqualInstruction* equal = new TreeExpression::EqualInstruction();
	equal->setSon(first);
	AutoPointer<TreeExpression::Expression> ris(equal);
	LVM->push(ris);
	return true;
}
